package com.kantboot.tool.area.repository;

import com.kantboot.tool.area.domain.entity.ToolAdArea;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface ToolAdAreaRepository extends JpaRepository<ToolAdArea, Long> {

    /**
     * 根据国家地区编码和父级地区编码查询
     */
    @Query("""
    FROM ToolAdArea
    WHERE stateAreaCode = :stateAreaCode
    AND parentAdCode = :parentAdCode""")
    List<ToolAdArea> getByStateAreaCodeAndParentAdCode(
            @Param("stateAreaCode") String stateAreaCode, @Param("parentAdCode") String parentAdCode);

    /**
     * 根据国家地区编码查询
     */
    @Query("""
    FROM ToolAdArea
    WHERE stateAreaCode = :stateAreaCode
    AND parentAdCode IS NULL OR parentAdCode = ""
    """)
    List<ToolAdArea> getByStateAreaCode(String stateAreaCode);

}
